package com.atguigu.yygh.shop.controller.api;

import com.atguigu.yygh.common.result.Result;
import com.atguigu.yygh.model.hosp.Schedule;
import com.atguigu.yygh.model.shop.Shop;
import com.atguigu.yygh.shop.service.DepartmentService;
import com.atguigu.yygh.shop.service.ShopService;
import com.atguigu.yygh.shop.service.ShopSetService;
import com.atguigu.yygh.shop.service.ScheduleService;
import com.atguigu.yygh.vo.hosp.DepartmentVo;
import com.atguigu.yygh.vo.hosp.ScheduleOrderVo;
import com.atguigu.yygh.vo.shop.ShopQueryVo;
import com.atguigu.yygh.vo.order.SignInfoVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/shop/shop")
public class ShopApiController {

    @Autowired
    private ShopService shopService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    @Autowired
    private ShopSetService shopSetService;

    @ApiOperation(value = "查询店铺列表")
    @GetMapping("findShopList/{page}/{limit}")
    public Result findShopList(@PathVariable Integer page,
                               @PathVariable Integer limit,
                               ShopQueryVo shopQueryVo) {
        Page<Shop> shops = shopService.selectShopPage(page, limit, shopQueryVo);
        return Result.ok(shops);
    }

    @ApiOperation(value = "根据店铺名称查询")
    @GetMapping("findByShopName/{shopname}")
    public Result findByShopName(@PathVariable String shopname) {
        List<Shop> list = shopService.findByShopName(shopname);
        return Result.ok(list);
    }

    @ApiOperation(value = "根据店铺编号获取科室")
    @GetMapping("department/{shopcode}")
    public Result index(@PathVariable String shopcode) {
        List<DepartmentVo> list = departmentService.findDeptTree(shopcode);
        return Result.ok(list);
    }

    @ApiOperation(value = "根据店铺编号获取店铺预约挂号详情")
    @GetMapping("findShopDetail/{shopcode}")
    public Result item(@PathVariable String shopcode) {
        Map<String, Object> map = shopService.item(shopcode);
        return Result.ok(map);
    }

    @ApiOperation(value = "获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{shopcode}/{depcode}")
    public Result getBookingSchedule(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable Integer page,
            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable Integer limit,
            @ApiParam(name = "shopcode", value = "店铺code", required = true)
            @PathVariable String shopcode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode) {
        return Result.ok(scheduleService.getBookingScheduleRule(page, limit, shopcode, depcode));
    }

    @ApiOperation(value = "获取排班数据")
    @GetMapping("auth/findScheduleList/{shopcode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @ApiParam(name = "shopcode", value = "店铺code", required = true)
            @PathVariable String shopcode,
            @ApiParam(name = "depcode", value = "科室code", required = true)
            @PathVariable String depcode,
            @ApiParam(name = "workDate", value = "排班日期", required = true)
            @PathVariable String workDate) {
        return Result.ok(scheduleService.getDetailSchedule(shopcode, depcode, workDate));
    }

    @ApiOperation(value = "获取排班id获取排班数据")
    @GetMapping("getSchedule/{scheduleId}")
    public Result getSchedule(@PathVariable String scheduleId) {
        Schedule schedule = scheduleService.getScheduleId(scheduleId);
        return Result.ok(schedule);
    }

    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(
            @ApiParam(name = "scheduleId", value = "排班id", required = true)
            @PathVariable("scheduleId") String scheduleId) {
        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    @ApiOperation(value = "获取店铺签名信息")
    @GetMapping("inner/getSignInfoVo/{shopcode}")
    public SignInfoVo getSignInfoVo(
            @ApiParam(name = "shopcode", value = "店铺code", required = true)
            @PathVariable("shopcode") String shopcode) {
        return shopSetService.getSignInfoVo(shopcode);
    }

}
